﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace YmSoft.Kblog.Module
{
    public class LoginManagerModule : IHttpModule
    {

        #region 全局登录控制检测

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        public void Init(HttpApplication context)
        {
            context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
        }

        void context_AcquireRequestState(object sender, EventArgs e)
        {

            HttpApplication app = (HttpApplication)sender;
            if (System.IO.Path.GetExtension(app.Context.Request.CurrentExecutionFilePath).Equals(".aspx") && app.Context.Request.CurrentExecutionFilePath.IndexOf("/Admin/") != -1)
            {
                if (app.Context.Request.CurrentExecutionFilePath.Equals("/Admin/Login.aspx"))
                {
                    app.Context.Session["ReturnUrl"] = "Default.aspx";
                }
                else
                {
                    if (app.Context.Session["LoginState"] == null)
                    {
                        app.Context.Session["ReturnUrl"] = app.Context.Request.CurrentExecutionFilePath;
                        app.Context.Response.Redirect("Login.aspx");
                    }
                }

            }

        }

        #endregion
    }

}
